<?php

namespace api\libs\swoft;

use api\libs\swoft\core\SwoftCore;
use api\libs\swoft\ifc\SwoftClient;
use yii\helpers\Json;

class SwoftUser extends SwoftClient
{
    public function loginByToken($arr_request) {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'web/users/login-by-token';
        $options[SwoftCore::SWOFT_QUERY_STRING] = $arr_request;
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_GET;
        return $this->sendRequest($options);
    }
    public function acceptPosition($data,$access_token) {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'app/users/accept-position';
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/x-www-form-urlencoded';
        $options[SwoftCore::SWOFT_CONTENT] = http_build_query($this->convertParams($data));
        return $this->sendRequest($options);
    }

    public function login($data) {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'app/users/login';
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_QUERY_STRING] = [];
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/x-www-form-urlencoded';
        $options[SwoftCore::SWOFT_CONTENT] = http_build_query($this->convertParams($data));
        return $this->sendRequest($options);
    }

    public function logout($data) {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'app/users/logout';
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_QUERY_STRING] = [];
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/json';
        $options[SwoftCore::SWOFT_CONTENT] = Json::encode($data);
        return $this->sendRequest($options);
    }

    public function signin($data,$access_token) {
        $options[SwoftCore::SWOFT_RESOURCE] = $this->getBaseUri() . 'app/users/signin';
        $options[SwoftCore::SWOFT_QUERY_STRING] = array('token' => $access_token);
        $options[SwoftCore::SWOFT_METHOD] = SwoftCore::SWOFT_HTTP_POST;
        $options[SwoftCore::SWOFT_CONTENT_TYPE] = 'application/x-www-form-urlencoded';
        $options[SwoftCore::SWOFT_CONTENT] = http_build_query($this->convertParams($data));
        return $this->sendRequest($options);
    }
}